/**
 * 
 */
package any.tag.server.resource;

import java.io.IOException;

import net.sf.json.JsonConfig;

import org.apache.commons.lang.Validate;
import org.restlet.data.CharacterSet;
import org.restlet.data.MediaType;
import org.restlet.resource.Representation;
import org.restlet.resource.Variant;

import any.restlet.JSONRepresentation;
import any.restlet.helper.RepresentationHandler;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
public class TagRepresentationHandler implements RepresentationHandler {
    private JsonConfig jsonConfig;
    public void setJsonConfig(final JsonConfig jsonConfig) {
        this.jsonConfig = jsonConfig;
    }

    /*
     * (non-Javadoc)
     * 
     * @see any.restlet.helper.RepresentationHandler#toEntity(org.restlet.resource.Representation)
     */
    public Object toEntity(final Representation representation) throws IOException {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see any.restlet.helper.RepresentationHandler#toRepresentation(java.lang.Object,
     *      org.restlet.resource.Variant)
     */
    public Representation toRepresentation(final Object entity, final Variant variant) {
        Validate.notNull(entity);
        Representation rep = null;
        final MediaType mediaType = variant.getMediaType();
        if (mediaType.equals(MediaType.APPLICATION_JSON, true)) {
            rep = new JSONRepresentation(entity, jsonConfig, mediaType);
            rep.setCharacterSet(CharacterSet.UTF_8);
        }
        return rep;
    }

}
